## This is R code for "The Demand for Insurance: Incorporating the Severity of
## Losing Office into the Insurance Model of Judicial Independence"
## Robustness check
## Rolling window previous 10 years

rm(list = ls())
## install.packages("pacman") #load all packages
## remotes::install_github("chrisadolph/simcf") since simcf cannot be directly installed
pacman::p_load(
  tidyverse,this.path,texreg,MASS,AER,ivregEX,ivpack,simcf,arm,stargazer,ivmodel
)
## set working directory
setwd(this.path::here(..=1))
## read data
load("Data/dat.RData")

## Preparation -----------------------------------------------------------------
## a. Select the threats variables
dat <- dat %>%
  mutate(
    threat = threat_roll10,
    threatS = threatS_roll10
  )

## b. Specify the directories for table and figure
robustness_dir <- "./RobustnessCheck/roll10/"
dir.create(robustness_dir, showWarnings = FALSE)
dir_table <- paste0(robustness_dir, "maintable.tex")
dir_figure <- paste0(robustness_dir, "plot_me.pdf") 

## Run everything --------------------------------------------------------------
source("Code/EstimationTableFigure.R")

## double check figure
plot_me

ggsave(plot_me, file=dir_figure)
